package at.ac.univie.zsu.aguataplan.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;

import at.ac.univie.zsu.aguataplan.util.TimeUtil;

/**
 * @author gerry
 * 
 */
@Entity
public class DetectedEvent {
	@Id
	@GeneratedValue(strategy = GenerationType.TABLE)
	@Column
	private Long id;

	@Version
	@Column
	private Integer version;

	@NotNull
	@Column
	private float detPosition;

	@NotNull
	@Column
	private long detTime;

	@NotNull
	@Column
	private double length;

	@ManyToOne
	private Video refVideo;

	@ManyToOne
	private Event refEvent;

	@ManyToOne
	private EventAttribute refEventAttribute;

	@ManyToOne
	private EventAttributeValue refEventAttributeValue;

	// ------

	@OneToOne
	private EventDescription refEventDescription;

	@ManyToOne
	private Coach refCoach;

	// ----------------------------------------------------
	// CONSTRUCTOR
	// ----------------------------------------------------

	public DetectedEvent() {

	}

	// ----------------------------------------------------
	// METHODS
	// ----------------------------------------------------

	public String getPositionString() {
		return TimeUtil.millisToShortDHMS(getDetTime());
	}

	public String toString() {
		return TimeUtil.millisToShortDHMS(detTime) + ": " + refEvent.toString() + " - " + refEventAttribute.toString()
				+ " - " + refEventAttributeValue.toString();
	}

	public String toStringExtended() {
		StringBuilder sb = new StringBuilder();
		sb.append("DetTime: ").append(getDetTime()).append(", ");
		sb.append("Id: ").append(getId()).append(", ");
		sb.append("Length: ").append(getLength()).append(", ");
		// sb.append("Name: ").append(getName()).append(", ");
		// sb.append("RefAttributeValue: ")
		// .append(getRefEventAttributeValue() == null ? "null" :
		// getRefEventAttributeValue().size()).append(", ");
		sb.append("RefCoach: ").append(getRefCoach()).append(", ");
		// sb.append("RefEvent: ").append(getRefEvent()).append(", ");
		sb.append("RefEventDescription: ").append(getRefEventDescription()).append(", ");
		sb.append("RefVideo: ").append(getRefVideo()).append(", ");
		sb.append("Version: ").append(getVersion());
		return sb.toString();
	}

	public String[] toStringExport() {
		List<String> list = new ArrayList<String>();
		list.add(TimeUtil.millisToShortDHMS(detTime) + "");
		list.add(refEvent.toString());
		list.add(refEventAttribute.toString());
		list.add(refEventAttributeValue.toString());
		return list.toArray(new String[] {});
	}

	public static String[] toStringExportHeadline() {
		List<String> list = new ArrayList<String>();
		list.add("Time");
		list.add("Event");
		list.add("EventAttribute");
		list.add("EventAttributeValue");
		return list.toArray(new String[] {});
	}

	// ----------------------------------------------------
	// GETTER & SETTER
	// ----------------------------------------------------

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public float getDetPosition() {
		return detPosition;
	}

	public void setDetPosition(float detPosition) {
		this.detPosition = detPosition;
	}

	public long getDetTime() {
		return detTime;
	}

	public void setDetTime(long detTime) {
		this.detTime = detTime;
	}

	public double getLength() {
		return length;
	}

	public void setLength(double length) {
		this.length = length;
	}

	public Video getRefVideo() {
		return refVideo;
	}

	public void setRefVideo(Video refVideo) {
		this.refVideo = refVideo;
	}

	public Event getRefEvent() {
		return refEvent;
	}

	public void setRefEvent(Event refEvent) {
		this.refEvent = refEvent;
	}

	public EventAttribute getRefEventAttribute() {
		return refEventAttribute;
	}

	public void setRefEventAttribute(EventAttribute refEventAttribute) {
		this.refEventAttribute = refEventAttribute;
	}

	public EventAttributeValue getRefEventAttributeValue() {
		return refEventAttributeValue;
	}

	public void setRefEventAttributeValue(EventAttributeValue refEventAttributeValue) {
		this.refEventAttributeValue = refEventAttributeValue;
	}

	public EventDescription getRefEventDescription() {
		return refEventDescription;
	}

	public void setRefEventDescription(EventDescription refEventDescription) {
		this.refEventDescription = refEventDescription;
	}

	public Coach getRefCoach() {
		return refCoach;
	}

	public void setRefCoach(Coach refCoach) {
		this.refCoach = refCoach;
	}

}
